package cn.wolfcode.cms.web.controller;

import cn.wolfcode.cms.annotation.PermissionName;
import cn.wolfcode.cms.domain.RecordExchange;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IRecordExchangeService;
import cn.wolfcode.cms.util.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//兑换记录
@Controller
@RequestMapping("recordExchange")
public class RecordExchangeController {

    @Autowired
    private IRecordExchangeService recordExchangeService;

    @RequiresPermissions("recordExchange:index")
    @PermissionName("兑换记录首页")
    @RequestMapping("")
    public String index() {
        recordExchangeService.list();
        return "recordExchange/list";
    }

    //兑换记录信息列表/带分页
    @RequiresPermissions("recordExchange:list")
    @PermissionName("兑换记录列表")
    @RequestMapping("list")
    @ResponseBody
    public Object list(QueryObject qo) {
        return recordExchangeService.query(qo);
    }


    //所有兑换记录信息数据/无分页
    @RequestMapping("listData")
    @ResponseBody
    public Object listData() {
        return recordExchangeService.list();
    }


    //兑换记录添加
    @RequiresPermissions("recordExchange:add")
    @PermissionName("兑换记录添加")
    @RequestMapping("save")
    @ResponseBody
    public Object save(RecordExchange entity, Long mid, Integer prenum, Long preid) {
        JSONResult result = new JSONResult();
        try {
            recordExchangeService.save(entity, mid, prenum, preid);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲,兑换失败咯");
        }
        return result;
    }
}